<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Supported queries - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/learning.lucene.queries.html">Inglês (English)</a></li>
    <li><a href="../pt-br/learning.lucene.queries.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="learning.lucene.searching.html">Searching</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="learning.lucene.html">Iniciando com o Zend_Search_Lucene</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="learning.lucene.pagination.html">Search result pagination</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="learning.lucene.queries" class="section"><div class="info"><h1 class="title">Supported queries</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Search_Lucene</span> and Java Lucene support a powerful query language.
        It allows searching for individual terms, phrases, ranges of terms; using wildcards and
        fuzzy search; combining queries using boolean operators; and so on.
    </p>

    <p class="para">
        A detailed query language description can be found in the <a href="zend.search.lucene.query-language.html" class="link">
            Zend_Search_Lucene component documentation</a>.
    </p>

    <p class="para">
        What follows are examples of some common query types and strategies.
    </p>

    <div class="example" id="learning.lucene.queries.keyword"><div class="info"><p><b>Example #1 Querying for a single word</b></p></div>
        

        <pre class="programlisting brush: text">
hello
</pre>


        <div class="example-contents"><p>
            Searches for the word &quot;hello&quot; through all document fields.
        </p></div>
    </div>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Default search field</b><br /></span>
        

        <p class="para">
            Important note! Java Lucene searches only through the &quot;contents&quot; field by default, but
            <span class="classname">Zend_Search_Lucene</span> searches through <em class="emphasis">all</em>
            fields. This behavior can be modified using the
             <span class="methodname">Zend_Search_Lucene::setDefaultSearchField($fieldName)</span> method.
        </p>
    </p></blockquote>

    <div class="example" id="learning.lucene.queries.multiple-words"><div class="info"><p><b>Example #2 Querying for multiple words</b></p></div>
        

        <pre class="programlisting brush: text">
hello dolly
</pre>


        <div class="example-contents"><p>
            Searches for two words. Both words are optional; at least one of them must be present in
            the result.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.required-words"><div class="info"><p><b>Example #3 Requiring words in a query</b></p></div>
        

        <pre class="programlisting brush: text">
+hello dolly
</pre>


        <div class="example-contents"><p>
            Searches for two words; &quot;hello&quot; is required, &quot;dolly&quot; is optional.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.prohibited-words"><div class="info"><p><b>Example #4 Prohibiting words in queried documents</b></p></div>
        

        <pre class="programlisting brush: text">
+hello -dolly
</pre>


        <div class="example-contents"><p>
            Searches for two words; &quot;hello&quot; is required, &#039;dolly&#039; is prohibited. In other words, if
            the document matches &quot;hello&quot;, but contains the word &quot;dolly&quot;, it will not be returned in
            the set of matches.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.phrases"><div class="info"><p><b>Example #5 Querying for phrases</b></p></div>
        

        <pre class="programlisting brush: text">
&quot;hello dolly&quot;
</pre>


        <div class="example-contents"><p>
            Searches for the phrase &quot;hello dolly&quot;; a document only matches if that exact string is
            present.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.fields"><div class="info"><p><b>Example #6 Querying against specific fields</b></p></div>
        

        <pre class="programlisting brush: text">
title:&quot;The Right Way&quot; AND text:go
</pre>


        <div class="example-contents"><p>
            Searches for the phrase &quot;The Right Way&quot; within the <span class="property">title</span> field and
            the word &quot;go&quot; within the <span class="property">text</span> field.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.fields-and-document"><div class="info"><p><b>Example #7 Querying against specific fields as well as the entire document</b></p></div>
        

        <pre class="programlisting brush: text">
title:&quot;The Right Way&quot; AND  go
</pre>


        <div class="example-contents"><p>
            Searches for the phrase &quot;The Right Way&quot; within the <span class="property">title</span> field and
            the word &quot;go&quot; word appearing in any field of the document.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.fields-and-document-alt"><div class="info"><p><b>Example #8 Querying against specific fields as well as the entire document (alternate)</b></p></div>
        

        <pre class="programlisting brush: text">
title:Do it right
</pre>


        <div class="example-contents"><p>
            Searches for the word &quot;Do&quot; within the <span class="property">title</span> field and the words
            &quot;it&quot; and &quot;right&quot; words through all fields; any single one matching will result in
            a document match.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.wildcard-question"><div class="info"><p><b>Example #9 Querying with the wildcard &quot;?&quot;</b></p></div>
        

        <pre class="programlisting brush: text">
te?t
</pre>


        <div class="example-contents"><p>
            Search for words matching the pattern &quot;te?t&quot;, where &quot;?&quot; is any single character.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.wildcard-asterisk"><div class="info"><p><b>Example #10 Querying with the wildcard &quot;*&quot;</b></p></div>
        

        <pre class="programlisting brush: text">
test*
</pre>


        <div class="example-contents"><p>
            Search for words matching the pattern &quot;test*&quot;, where &quot;*&quot; is any sequence of zero or more
            characters.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.range-inclusive"><div class="info"><p><b>Example #11 Querying for an inclusive range of terms</b></p></div>
        

        <pre class="programlisting brush: text">
mod_date:[20020101 TO 20030101]
</pre>


        <div class="example-contents"><p>
            Search for the range of terms (inclusive).
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.range-exclusive"><div class="info"><p><b>Example #12 Querying for an exclusive range of terms</b></p></div>
        

        <pre class="programlisting brush: text">
title:{Aida to Carmen}
</pre>


        <div class="example-contents"><p>
            Search for the range of terms (exclusive).
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.fuzzy"><div class="info"><p><b>Example #13 Fuzzy searches</b></p></div>
        

        <pre class="programlisting brush: text">
roam~
</pre>


        <div class="example-contents"><p>
            Fuzzy search for the word &quot;roam&quot;.
        </p></div>
    </div>

    <div class="example" id="learning.lucene.queries.boolean"><div class="info"><p><b>Example #14 Boolean searches</b></p></div>
        

        <pre class="programlisting brush: text">
(framework OR library) AND php
</pre>


        <div class="example-contents"><p>
            Boolean query.
        </p></div>
    </div>

    <p class="para">
        All supported queries can be constructed through <span class="classname">Zend_Search_Lucene</span>&#039;s
        <a href="zend.search.lucene.query-api.html" class="link"> query
            construction API</a>. Moreover, query parsing and query constructing may be
        combined:
    </p>

    <div class="example" id="learning.lucene.queries.combining"><div class="info"><p><b>Example #15 Combining parsed and constructed queries</b></p></div>
        

        <pre class="programlisting brush: php">
$userQuery = Zend_Search_Lucene_Search_QueryParser::parse($queryStr);

$query = new Zend_Search_Lucene_Search_Query_Boolean();
$query-&gt;addSubquery($userQuery, true  /* required */);
$query-&gt;addSubquery($constructedQuery, true  /* required */);
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="learning.lucene.searching.html">Searching</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="learning.lucene.html">Iniciando com o Zend_Search_Lucene</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="learning.lucene.pagination.html">Search result pagination</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="learning.html">Conhecendo o Zend Framework</a></li>
  <li class="header up"><a href="learning.lucene.html">Iniciando com o Zend_Search_Lucene</a></li>
  <li><a href="learning.lucene.intro.html">Zend_Search_Lucene Introduction</a></li>
  <li><a href="learning.lucene.index-structure.html">Lucene Index Structure</a></li>
  <li><a href="learning.lucene.index-opening.html">Index Opening and Creation</a></li>
  <li><a href="learning.lucene.indexing.html">Indexing</a></li>
  <li><a href="learning.lucene.searching.html">Searching</a></li>
  <li class="active"><a href="learning.lucene.queries.html">Supported queries</a></li>
  <li><a href="learning.lucene.pagination.html">Search result pagination</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>